<template>
  <view class="page">
    <view class="card" v-for="(item,index) in list"
      @click="jumpDatail(item.id,item.report_id,item.equipment,item.service_type)" :key='item.report_id'>
      <view class="ful">
        <view class="ful_left">
          报告类型
        </view>
        <view class="ful_right">
          {{item.service_type == 0 ? '维修' : (item.service_type == 1 ? '保养' : '返修')}}服务报告
        </view>
      </view>
      <view class="ful">
        <view class="ful_left">
          状态
        </view>
        <view class="ful_right">
          {{item.status == 1 ? '已完成' : '未完成'}}
        </view>
      </view>
      <view class="ful border">
        <view class="ful_left">
          结单时间
        </view>
        <view class="ful_right">
          {{item.statementtime_text || '无'}}
        </view>
      </view>
      <view class="dis">
        <image v-if="item.isFinish == 0 && item.forward_qrcode" src="../../static/index/code.png" mode=""
          class="img_code" @tap.stop="lockImage(item.forward_qrcode)"></image>
        <view class="btn">
          详情
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        id: null,
        page: 1,
        list: [],
        last_page: null
      }
    },
    onLoad(e) {
      this.id = e.id
    },
    onShow() {
      if (this.id) {
        this.page = 1
        this.list = []
        this.last_page = null
        this.getList()
      }
    },
    methods: {
      getList() {
        this.$https.post('/warranty/mainten', {
          warranty_id: this.id,
          page: this.page
        }).then(res => {
          this.last_page = res.data.last_page
          this.list = this.list.concat(res.data.data)
        }).catch(err => {
          console.log(err)
        })
      },
      lockImage(item) {
        let url = item.split(',')
        uni.previewImage({
          urls: [url[0]],
        })
      },
      jumpDatail(id, report_id, equipment, service_type) {
        let arr = ['CT', 'DR', 'DSA', '超声', 'MRI', 'DR/F', '小C']
        let res = arr.includes(equipment.pinpai.name)
        if (res) {
          if (service_type != 1) {
            uni.navigateTo({
              url: '../report_detail/report_detail?service_id=' + id + "&report_id=" + report_id
            })
          } else {
            uni.navigateTo({
              url: '../report_detail/report_detailNew?service_id=' + id + "&report_id=" + report_id
            })
          }
        } else {
          uni.navigateTo({
            url: '../report_detail/report_detail?service_id=' + id + "&report_id=" + report_id
          })
        }
      }
    },
    onReachBottom() {
      if (this.page != this.last_page) {
        this.page = this.page + 1
        this.getList()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .dis {
    display: flex;
    justify-content: flex-end;
    padding: 10rpx;
    align-items: center;

    .img_code {
      width: 64rpx;
      height: 64rpx;
      padding: 10rpx;
      box-sizing: border-box;
      margin-right: 440rpx;
    }
  }

  .btn {
    font-size: 28rpx;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #1A66FF;
    padding: 6rpx 32rpx;
    border-radius: 32rpx;
    opacity: 1;
    border: 2rpx solid #1A66FF;
  }

  .border {
    border-bottom: 2rpx solid #f7f8fb;
  }

  .page {
    background-color: #f7f8fb;
    min-height: 100vh;
    padding-bottom: 80rpx;
  }

  .ful {
    display: flex;
    justify-content: space-between;
  }

  .ful_left {
    color: #303030;
    padding: 20rpx;
  }

  .ful_right {
    padding: 20rpx;
  }

  .card {
    font-size: 28rpx;
    color: #999999;
    margin: 30rpx;
    background-color: #fff;
    padding: 10rpx;
    border-radius: 10rpx;
    box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  }
</style>